<template>
  <div class="el-main">
    <el-form ref="form" :model="richText" label-width="120px">
      <el-form-item label="新闻标题" prop="title">
        {{richText.title}}
      </el-form-item>
      <el-form-item v-show="false" label="id">
        <el-input v-model="richText.id"></el-input>
      </el-form-item>
      <el-form-item label="新闻内容" prop="content">
        <div v-html="richText.content"></div>
      </el-form-item>
      <el-form-item style="padding-top: 50px" prop="status">
        <el-input v-show="false" v-model="richText.type"></el-input>
      </el-form-item>
      <el-form-item style="padding-top: 50px" prop="status">
        <el-input v-show="false" v-model="richText.status"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="examine">审核通过</el-button>
        <el-button @click="exit">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "NewsExamine",
    data() {
      return {
        richText: {
          title: '',
          content: '',
          type: "",
          status: 0
        }
      }
    },
    methods: {
      examine() {
        let that = this;
        that.richText.status = 1;
        this.instance.post('/w/announcements', this.richText)
          .then(function (response) {
            that.$router.push({name: 'announcementDynamics'})
          })
          .catch(function (error) {
            console.log(error);
          });
      },
      findById() {
        let that = this;
        this.instance.get('/w/announcements/' + that.id)
          .then(function (response) {
            that.richText = response.data;
          })
          .catch(function (error) {
            console.log(error);
          });
      },
      exit() {
        this.$router.push({name: 'announcementDynamics'}) // 只能用 name
      }
    },
    mounted() {
      let that = this;
      if (that.id != undefined) {
        that.findById();
      }
    },
    created() {
      let that = this;
      that.richText.type = that.$route.query.type
      if (!!that.$route.query.id) {
        that.id = that.$route.query.id
      }
    }
  }
</script>

<style scoped lang="scss">
  .quill-editor {
    min-height: 200px;
  }


</style>
<style>
  .ql-editor {
    min-height: 200px;
  }
</style>
